﻿
using MediaPortal.Dialogs;
using MediaPortal.GUI.Library;
using MyMenu.action;

namespace MyMenu
{
    class GuiFactory
    {
        public static void HideMenu()
        {
            GUIWindowManager.CloseCurrentWindow();
            //((GUIDialogMenu)GUIWindowManager.GetWindow(
            // (int)GUIWindow.Window.WINDOW_DIALOG_MENU)).PreviousWindowId;
        }


        public static int toGUIDialogMenu(ShowMenu action)
        {
            GUIDialogMenu result = null;
         
            result = (GUIDialogMenu)GUIWindowManager.GetWindow(
             (int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (result == null)
            {
                return 0;
            }
            result.Reset();
            result.SetHeading(action.name);
            GUIListItem guiItem;
            foreach (action.Action actionTmp in action.actions)
            {
                guiItem = new GUIListItem();
                guiItem.Label = actionTmp.name;
                result.Add(guiItem);
            }
            result.SelectedLabel = 0;
            result.DoModal(GUIWindowManager.ActiveWindow);
            int selectedItem = result.SelectedId;
            result.Dispose();
            return selectedItem;
            
        }

        public static void ActivateWindow(int id)
        {
            GUIWindowManager.ActivateWindow(id);
        }

        public static bool toGuiDialogYesNo(string question)
        {          
            GUIDialogYesNo dialogYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow(
                            (int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
            dialogYesNo.SetHeading("Confirmation");
            dialogYesNo.SetLine(1, question);
            dialogYesNo.DoModal(GUIWindowManager.ActiveWindow);
            return dialogYesNo.IsConfirmed;
        }
    }
}
